package com.payment.ktb.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.SectionIndexer;
import android.widget.TextView;

import com.payment.ktb.R;
import com.payment.ktb.model.City;
import com.payment.ktb.model.VipMealEntity;
import com.payment.ktb.utils.LogUtil;
import com.payment.ktb.view.PinnedHeaderListView;

import java.util.List;
import java.util.Locale;

/**
 * Created by syd on 2016/5/8.
 */
public class MembershipCenterAdapter extends BaseAdapter  {

    Context mContext;
    List<VipMealEntity> listData;

    public MembershipCenterAdapter(Context mContext, List<VipMealEntity> listData) {

        this.mContext = mContext;
        this.listData = listData;

    }



    @Override
    public int getCount() {
        return listData.size();
    }

    @Override
    public Object getItem(int position) {
        return listData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder mViewHolder = null;
        if (convertView == null) {
            mViewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_membershipcenter_item, null);
            mViewHolder.tv_membershipcenter_mealtitle = (TextView) convertView.findViewById(R.id.tv_membershipcenter_mealtitle);
            mViewHolder.tv_membershipcenter_mealprice = (TextView) convertView.findViewById(R.id.tv_membershipcenter_mealprice);
            mViewHolder.rl_membershipcenter_meal = (RelativeLayout) convertView.findViewById(R.id.rl_membershipcenter_meal);
            convertView.setTag(mViewHolder);
        } else {
            mViewHolder = (ViewHolder) convertView.getTag();
        }

        mViewHolder.tv_membershipcenter_mealtitle.setText(listData.get(position).getTitle());
        mViewHolder.tv_membershipcenter_mealprice.setText("¥ " + Integer.valueOf(listData.get(position).getPrice())/100);

        if (listData.get(position).isSelect()) {
            mViewHolder.rl_membershipcenter_meal.setBackgroundColor(mContext.getResources().getColor(R.color.vip_taocan));
        }else {
            mViewHolder.rl_membershipcenter_meal.setBackgroundColor(mContext.getResources().getColor(R.color.white));
        }

        return convertView;
    }


    private class ViewHolder {
        TextView tv_membershipcenter_mealtitle ;
        TextView tv_membershipcenter_mealprice;
        RelativeLayout rl_membershipcenter_meal;
    }


    private String handleFen2Yuan(String fen) {
        if (fen.equals("0")) {
            return "0.00";
        }
        double srcFen = Double.valueOf(fen);
        double roundSrcFen = Math.round(srcFen);
        return String.valueOf(roundSrcFen/100);
    }

}

